#! /usr/bin/env node

const data = require('./blog-demo/data.js'), 
      fs = require('fs'),
      http = require('http');
if(!fs.existsSync('./blog-demo/chapters.html')){
  console.error('chapters.html文件不存在！');
  process.exit(1);
}
const html = fs.readFileSync('./blog-demo/chapters.html').toString('utf8');
http.createServer((req, res) => {
  if(req.url === '/'){
    res.end(html);
  } else if(req.url === '/getlist'){
    res.end(JSON.stringify(data));
  } 
  /*else{
    res.statusCode(404);
    res.end(`<h1>Not Found</h1>`);
  }*/
}).listen(8080);
